package cn.gx.kevin.dao.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.gx.kevin.dao.IOrgDao;
import cn.gx.kevin.dao.impl.BaseDao;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;
import cn.gx.kevin.domain.Org;

/**
*Generate by Kevin's CodeBuilder
**/
@Repository(value="orgDao")
public class OrgDao extends BaseDao<Org, String> implements IOrgDao {
	
	private static final String SQLID_UPDATEPID = "updatePid";
	private static final String SQLID_GET_PARENT_ORG = "selectParentOrg";
	private static final String SQLID_selectChildsByPid  ="selectChildsByPid";

	@Override
	public int updatePid(Map<String, Object> params) throws Exception {
		return getSqlSession().update(namespace + "." + SQLID_UPDATEPID, params);
	}

	@Override
	public Org selectParentOrg(String id) throws Exception {
		SqlSession session = getSqlSession();
		Org org = session.selectOne(namespace + "." + SQLID_GET_PARENT_ORG,id);
		return org;
	}

	@Override
	public List<Org> selectChildsByPid(List<String> pidList) throws Exception {
		SqlSession session = getSqlSession();
		Map<String,Object> params = new HashMap<>();
		params.put("pidList",pidList);
		List<Org> org = session.selectList(namespace + "." + SQLID_selectChildsByPid,params);
		return org;
	}
}
